home *** CD-ROM | disk | FTP | other *** search
/ Aminet 31 / Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso / Aminet / dev / gui / gui4cli.lha / Gui4Cli / Ext / GCSound / src / sound.h < prev   
Text File  |  1999-04-21  |  5KB  |  150 lines

  1.  
  2.  
  3. // ==================================================================
  4. //    playsound
  5. //    will start the sound and return - msg reply is in gcsound.c
  6. // ==================================================================
  7.  
  8. playsound (struct myhandle *h,
  9.          struct DosLibrary *DOSBase, struct ExecBase *SysBase)
  10. {
  11.    UBYTE  channels[] = { 1,2,4,8 };   // array for requesting channel
  12.    LONG   dev_error  = 1;  // 0 = device was opened ok
  13.  
  14.    // struct DosLibrary *DOSBase;
  15.    // struct ExecBase *SysBase;
  16.    // DOSBase=h->bs->dosbase; SysBase=h->bs->sysbase;
  17.  
  18.    // ----------- Open audio.device & get next available channel
  19.  
  20.    h->io1.ioa_Request.io_Message.mn_ReplyPort   = h->bs->soundport;
  21.    h->io1.ioa_Request.io_Message.mn_Node.ln_Pri = 127;    // No stealing!
  22.    h->io1.ioa_AllocKey  = 0;                 // filled by OpenDevice
  23.    h->io1.ioa_Data      = channels;          // ask for any channel
  24.    h->io1.ioa_Length    = sizeof(channels);
  25.  
  26.    if (dev_error = OpenDevice(AUDIONAME, 0L, (struct IORequest *)&h->io1, 0L))
  27.       return(0);
  28.  
  29.    // ----------- Set Up Audio IO Blocks for Sample Playing
  30.  
  31.    h->io1.ioa_Request.io_Command = CMD_WRITE;
  32.    h->io1.ioa_Request.io_Flags   = ADIOF_PERVOL;
  33.  
  34.    h->io1.ioa_Length  = h->buffsize;  // sample length
  35.    h->io1.ioa_Volume  = (UWORD)h->volume;
  36.    h->io1.ioa_Period  = (UWORD)h->speed;
  37.  
  38.    // pass times to play only for small samples
  39.    if (h->fp == NULL) 
  40.        h->io1.ioa_Cycles = (UWORD)h->times; // 0=forever
  41.    else
  42.        h->io1.ioa_Cycles = 1;
  43.  
  44.    h->played = 0;
  45.  
  46.    // ----------- clone structures so they're the same
  47.  
  48.    h->io2 = h->io1;
  49.  
  50.    // ----------- set their data
  51.  
  52.    h->io1.ioa_Data = h->buff1;
  53.    h->io2.ioa_Data = h->buff2;
  54.  
  55.    // ----------- Run the sample 
  56.  
  57.    if (h->fp == NULL)      // ---------- file was closed = small sample
  58.    {
  59.        BeginIO ((struct IORequest *)&h->io1);
  60.        h->remain = 0;  h->out1 = 1;
  61.    }
  62.  
  63.    else                    // ----------- large sample
  64.    {
  65.        BeginIO ((struct IORequest *)&h->io1);  // Start up the first 2 blocks
  66.        BeginIO ((struct IORequest *)&h->io2);
  67.        h->remain = h->bodylength - (h->buffsize * 2);  // remaining data length
  68.        h->out1 = h->out2 = 1;   // both messages are outstanding
  69.        h->reload = 1; // flag to reload sample before replaying
  70.    }
  71.    return (1);
  72. }
  73.  
  74. // ==================================================================
  75. //     setVolSpeed
  76. //    set the volume &/or speed of a playing sample
  77. // ==================================================================
  78. setVolSpeed (struct myhandle *h)
  79. {
  80.    struct IOAudio *io;        // new msg - FREEVEC AT GCSOUND.C!!
  81.    struct DosLibrary *DOSBase;
  82.    struct ExecBase *SysBase;
  83.    if (!h) return(0);
  84.    DOSBase=h->bs->dosbase; SysBase=h->bs->sysbase;
  85.  
  86.    // change fields, if sample is playing
  87.    if (h->out1 || h->out2)
  88.    {
  89.       if (!(io = (struct IOAudio *)AllocVec(sizeof(struct IOAudio), CLEANMEM)))
  90.          return(0);
  91.       *io = h->io1;        // clone the request
  92.       io->ioa_Request.io_Command = ADCMD_PERVOL;
  93.       io->ioa_Request.io_Flags   = IOF_QUICK;
  94.       io->ioa_Data    = NULL;
  95.       io->ioa_Length  = 0;
  96.       io->ioa_Volume  = (UWORD)h->volume;
  97.       io->ioa_Period  = (UWORD)h->speed;
  98.       BeginIO ((struct IORequest *)io);
  99.    }
  100.  
  101.    // set also the normal structures
  102.    h->io1.ioa_Volume  = (UWORD)h->volume;
  103.    h->io1.ioa_Period  = (UWORD)h->speed;
  104.    h->io2.ioa_Volume  = (UWORD)h->volume;
  105.    h->io2.ioa_Period  = (UWORD)h->speed;
  106.  
  107.    return (1);
  108.    // reply in gcsound.c
  109. }
  110.  
  111. // ==================================================================
  112. //     stopsound
  113. //    abort the sound - (wait for replies in gcsound.c)
  114. // ==================================================================
  115. void abortsound (struct myhandle *h)
  116. {
  117.    struct DosLibrary *DOSBase;
  118.    struct ExecBase *SysBase;
  119.    if (!h) return;
  120.    DOSBase=h->bs->dosbase; SysBase=h->bs->sysbase;
  121.  
  122.    if (h->out1)    // if it's outstanding, abort it..
  123.       AbortIO ((struct IORequest *)&h->io1);
  124.    if (h->out2)
  125.       AbortIO ((struct IORequest *)&h->io2);
  126.    h->remain = 0;
  127.    h->played = h->times;
  128. }
  129.  
  130. // ==================================================================
  131. // get constant (magic stuff you just do and don't ask why..)
  132. // ==================================================================
  133. BOOL getconstant (struct base *bs)
  134. {
  135.    struct GfxBase *GfxBase;
  136.    struct ExecBase *SysBase;
  137.    SysBase=bs->sysbase;
  138.  
  139.    if (GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0L))
  140.    {
  141.       if (GfxBase->DisplayFlags & PAL) bs->clock=3546895L; // PAL clock
  142.       else  bs->clock=3579545L;                            // NTSC clock
  143.       CloseLibrary ((struct Library *)GfxBase);
  144.       return (1);
  145.    }
  146.    return (0);
  147. }
  148.  
  149.  
  150.